<template>
  <!--页面搜索框 -->
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="认证类型" prop="type">
                <el-select v-model="queryParams.type" placeholder="认证类型" clearable style="width: 240px">
                    <el-option v-for="dict in authTypeDict" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="审核结果" prop="status">
                <el-select v-model="queryParams.status" placeholder="审核结果" clearable style="width: 240px">
                    <el-option v-for="dict in dict.type.auth_status" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['system:role:export']">导出</el-button>
            </el-col> -->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <!--显示的申请资料概况列表-->
        <el-table v-loading="loading" :data="authList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="用户名称" prop="examine_json.name" :show-overflow-tooltip="true" width="150" />
            <el-table-column label="认证类型" align="center" width="150">
                <template slot-scope="{row}">
                    {{ authTypeDict[row.authType - 1].label }}
                </template>
            </el-table-column>
            <el-table-column label="提交时间" align="center" prop="applyTime" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.applyTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="审核结果" align="center" width="150">
                <template slot-scope="{row}">
                    {{ dict.type.auth_status[row.examineResultStatus].label}}
                </template>
            </el-table-column>
            <el-table-column label="审查时间" align="center" prop="examineTime" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.examineTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="{row}">
                    <el-button size="mini" type="text" icon="el-icon-view"
                        @click="open = true; rowInfo = row.examine_json; status = row.examineResultStatus; type = row.authType; form.id = row.id">详情</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
      <!--审核按钮-->
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.pagesize"
            @pagination="getList" />
        <el-dialog :title="title" :visible.sync="open" width="1050px" append-to-body>
            <AuthInfo :rowInfo="rowInfo" :type="type"></AuthInfo>
            <div v-if="status == 1" slot="footer" class="dialog-footer">
                <el-button type="primary" @click="examineAuth(3)">审核通过</el-button>
                <el-button @click="authError = true">审核不通过</el-button>
            </div>

        </el-dialog>
      <!--遮罩：填写驳回原因-->
        <el-dialog title="审核不通过原因" :visible.sync="authError">
            <el-input type="textarea" :rows="3" placeholder="请输入原因" v-model="form.examineResultMessage">
            </el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="authError = false; form = {}">取 消</el-button>
                <el-button type="primary" @click="examineAuth(2)">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>
  
<script>
import { listAuth, delAuth, examine } from "@/api/system/auth";
import AuthInfo from "@/views/admin/system/auth/AuthInfo"

export default {
    name: "Auth",
    dicts: ['auth_status'],
    components: { AuthInfo },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                type: '',
                status: '0',
                page: 1,
                pagesize: 10,
            },

            // 表单校验
            rules: {
                roleName: [
                    { required: true, message: "角色名称不能为空", trigger: "blur" }
                ],
            },
            authTypeDict: [
                { value: 1, label: '设计师' },
                { value: 2, label: '工作室' },
                { value: 3, label: '企业' },
            ],
            //详情当前认证信息行信息
            rowInfo: '',
            authList: [],
            authError: false,
            form: {
                examineResultStatus: '',
                examineResultMessage: '',
                id: 0,
            },
            type: '',
            status: '0'
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询认证信息列表 */
        getList() {

            this.loading = true;
            listAuth(this.queryParams).then(response => {
                this.authList = response.data;
                this.total = response.total_record;
            }
            );
            this.loading = false;
        },
        // 表单重置
        reset() {
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const id = row.id
            this.$modal.confirm(`是否确认删除信息为${row.id}的数据项？`).then(function () {
                return delAuth(id);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        //审核
        examineAuth(status) {
            examine({
                id: this.form.id,
                examineResultStatus: status,
                examineResultMessage: this.form.examineResultMessage
            }).then((res) => {
                this.$modal.msgSuccess("审核成功");
                this.authError = false
                this.open = false
                this.getList()
            })
        },

        // /** 导出按钮操作 */
        // handleExport() {
        //     this.download('system/role/export', {
        //         ...this.queryParams
        //     }, `role_${new Date().getTime()}.xlsx`)
        // }
    }
};
</script>
  